package com.zhangxiaofanfan.hotcode.third;

/**
 * <a href="https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-100-liked">盛最多水的容器</a>
 *
 * @author zhangxiaofanfan
 * @date 2024-05-21 23:06:51
 */
public class HotCode005 {
    public static void main(String[] args) {

    }

    public int maxArea(int[] height) {
        int maxArea = 0;
        int indexLeft = 0;
        int indexRight = height.length - 1;
        while (indexLeft < indexRight) {
            int area = (indexRight - indexLeft) * (Math.min(height[indexLeft], height[indexRight]));
            maxArea = Math.max(area, maxArea);
            if (height[indexLeft] < height[indexRight]) {
                indexLeft++;
            } else {
                indexRight--;
            }
        }
        return maxArea;
    }
}
